import random
import string
from conn import mysql


def create_table():
    sql = """
                CREATE TABLE `users` (
                `id` int(11) NOT NULL AUTO_INCREMENT,
                `name` varchar(255) collate utf8_bin not null,
                `email` varchar(255) COLLATE utf8_bin NOT NULL,
                `password` varchar(255) COLLATE utf8_bin NOT NULL,
                PRIMARY KEY (`id`)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
                AUTO_INCREMENT=1 ;
                """
    mysql.upsert(sql)


def add_data():
    for _ in range(10**8):
        email = str(random.randrange(1000000, 9999999)) + \
            random.choice(['@qq.com', '@163.com', '@foxmail.com', '@gmail.com'])
        password = ''.join(random.sample(string.ascii_letters + string.digits, 8))
        firstname = random.choice(['dong', 'zhao', 'tian', 'zhang', 'li', 'hong',
                                  'xiao', 'si', 'gao', 'wang', 'ha', 'he', 'bei', 'tai'])
        lastname = random.choice(['san', 'wu', 'wei', 'hong', 'bai', 'si', 'xing', 'hong', 'ha',
                                 'he', 'fang', 'yu', 'bai', 'xiaojuan', 'ruidong', 'yibing', 'yifan'])
        name = firstname + lastname
        data = {'name': name, 'email': email, 'password': password}
        sql = "INSERT INTO `users` (`name`,`email`, `password`) VALUES (%(name)s,%(email)s, %(password)s)"
        mysql.upsert(sql, data)
        print("更新完毕")


if __name__ == '__main__':
    #create_table()
    add_data()
